//*************************************************************************************
//* 作    者： 
//* 创建时间： 2021-10-11 08:00:59
//*  描    述：

//* ************************************************************************************
using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;

/// <summary>
/// MonoBehaiver
/// <summary>
public class FerrisWheel : MonoBehaviour {
    [SerializeField]
    private Renderer m_viewRender;
    [SerializeField]
    protected int m_rotateSpeed = 5;
    protected Vector3[] m_childPositions;
    protected float m_currentAngle;
    protected int m_timer;
    private void OnEnable()
    {
        m_timer = TimerAgent.Instance.RegistLoop(RefreshRotation,0.1f);
    }

    private void OnDisable()
    {
        TimerAgent.Instance.StopTimer(m_timer);
    }

    private bool RefreshRotation()
    {
        if(m_viewRender && !m_viewRender.isVisible)
        {
            return false;
        }    

        m_currentAngle += m_rotateSpeed * 0.1f;
        m_currentAngle %= 360;
        transform.localEulerAngles = new Vector3(0, 0, m_currentAngle);
        for (int i = 0; i < transform.childCount; i++)
        {
            transform.GetChild(i).rotation = Quaternion.identity;
        }
        return !isActiveAndEnabled;
    }
}
